package com.mhgis.user.server.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.mhgis.user.server.entity.User;
import com.mhgis.user.server.repository.UserRepository;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;


@Api("user相关 api")
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
  	private UserRepository userRepository;
  
  	@ApiOperation("根据ID获取用户信息")
	@ApiImplicitParams({
		@ApiImplicitParam(paramType="query",name="id",dataType="long",required=true,value="用户的id",defaultValue="1"
				)
	})
	@ApiResponses({
		@ApiResponse(code=400,message="请求参数没填好"),
		@ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
	})
	@RequestMapping(value="/findById/{id}",method=RequestMethod.GET)
   public User findById(@PathVariable("id") Long id) {
      User findOne = this.userRepository.getOne(id);
      return findOne;

  		
   }
  	
  	@ApiOperation("根据ID获取用户信息")
	@ApiImplicitParams({
		@ApiImplicitParam(paramType="query",name="id",dataType="long",required=true,value="用户的id",defaultValue="1"
				)
	})
	@ApiResponses({
		@ApiResponse(code=400,message="请求参数没填好"),
		@ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
	})
	@RequestMapping(value="/findByItest/{id}",method=RequestMethod.GET)
  	 public User findByIdtest(@PathVariable("id") Long id) {
  	   
  	  		
  	  		User s= new User();
  	  		s.setId(id);
  	  		s.setName("name" + id);
  	  		s.setBirthday(new Date());
  	  		s.setSex("男");
  	  		return s;
  	  		
  	   }
}




